<template>
  <div class="app-container" style="padding: 10px;">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
          <span style="font-weight: bold;color: #0099ff;font-size: 16px;">筛选条件</span>
      </div> 
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px" label-position="top">
        <el-form-item label="单据日期" prop="vouchdate">
          <el-input
            v-model="queryParams.vouchdate"
            placeholder="请输入单据日期"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单据编号" prop="code">
          <el-input
            v-model="queryParams.code"
            placeholder="请输入单据编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="业务组织" prop="orgName">
          <el-input
            v-model="queryParams.orgName"
            placeholder="请输入业务组织"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        
        <el-form-item label="供货供应商" prop="vendorName">
          <el-input
            v-model="queryParams.vendorName"
            placeholder="请输入供货供应商"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物料编码" prop="productCcode">
          <el-input
            v-model="queryParams.productCcode"
            placeholder="请输入物料编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物料名称" prop="productCname">
          <el-input
            v-model="queryParams.productCname"
            placeholder="请输入物料名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="结算日期" prop="balancedate">
          <el-input
            v-model="queryParams.balancedate"
            placeholder="请输入结算日期"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-card class="box-card" style="margin-top: 10px;">
      <div slot="header" class="clearfix">
          <span style="font-weight: bold;color: #0099ff;font-size: 16px;">结果列表</span>
      </div>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="SysYongyouCgfpList" border height="550">
        <el-table-column label="单据日期" align="center" prop="vouchdate" width="100" fixed />
        <el-table-column label="单据编号" align="center" prop="code" width="200" fixed />
        <el-table-column label="业务组织" align="left" prop="orgName" width="240" />
        <el-table-column label="供货供应商" align="left" prop="vendorName" width="300" />
        <el-table-column label="收票组织" align="left" width="300" prop="ininvoiceorgName"  />
        <el-table-column label="交易类型" align="center" prop="bustypeName" width="120" />
        <el-table-column label="物料编码" width="160" align="center" prop="productCcode" />
        <el-table-column label="单据状态" align="center" prop="status">
          <template slot-scope="scope">
            <span v-if="scope.row.status=='0'" style="color: blue;">未审核</span>
            <span v-if="scope.row.status=='1'" style="color: green;">已审核</span>
            <span v-if="scope.row.status=='2'" style="color: gray;">已关闭</span>
            <span v-if="scope.row.status=='3'" style="color: red;">审核中</span>
          </template>
        </el-table-column>
        <el-table-column label="物料名称" width="400" align="left" prop="productCname" />
        <el-table-column label="数量" align="center" prop="qty" />
        <el-table-column label="主计量名称" align="center" prop="unitName" width="120" />
        <el-table-column label="含税单价" align="center" prop="oritaxunitprice" />
        <el-table-column label="含税金额" align="center" prop="listorisum" />
        <el-table-column label="结算日期" align="center" prop="balancedate" width="100" />
        <el-table-column label="备注" align="center" prop="memo" width="120" />
        <el-table-column label="关联采购订单code" align="center" prop="purinvoicesFirstupcode" width="200" />
        <el-table-column label="关联采购入库单code" align="center" prop="upcode" width="200" />
        <!-- <el-table-column label="操作" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-tickets"
              @click="handleUpdate(scope.row)"
            >查看详情</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { listSysYongyouCgfp, getSysYongyouCgfp, delSysYongyouCgfp, addSysYongyouCgfp, updateSysYongyouCgfp } from "@/api/system/cg/cgfp";

export default {
  name: "SysYongyouCgfp",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购发票表格数据
      SysYongyouCgfpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vouchdate: null,
        code: null,
        orgName: null,
        ininvoiceorgName: null,
        bustypeName: null,
        vendorName: null,
        productCcode: null,
        status: null,
        productCname: null,
        qty: null,
        unitName: null,
        oritaxunitprice: null,
        listorisum: null,
        balancedate: null,
        memo: null,
        purinvoicesFirstupcode: null,
        upcode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购发票列表 */
    getList() {
      this.loading = true;
      listSysYongyouCgfp(this.queryParams).then(response => {
        this.SysYongyouCgfpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        vouchdate: null,
        code: null,
        orgName: null,
        ininvoiceorgName: null,
        bustypeName: null,
        vendorName: null,
        productCcode: null,
        status: null,
        productCname: null,
        qty: null,
        unitName: null,
        oritaxunitprice: null,
        listorisum: null,
        balancedate: null,
        memo: null,
        purinvoicesFirstupcode: null,
        upcode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.vouchdate)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采购发票";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const vouchdate = row.vouchdate || this.ids
      getSysYongyouCgfp(vouchdate).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改采购发票";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.vouchdate != null) {
            updateSysYongyouCgfp(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSysYongyouCgfp(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const vouchdates = row.vouchdate || this.ids;
      this.$modal.confirm('是否确认删除采购发票编号为"' + vouchdates + '"的数据项？').then(function() {
        return delSysYongyouCgfp(vouchdates);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/yycgfp/export', {
        ...this.queryParams
      }, `采购发票_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
